/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bff.spi.utils;

import com.inspur.edp.bef.api.lcp.AuthInfo;
import com.inspur.edp.bff.spi.builtin.BffAuthConfig;
import com.inspur.edp.bff.spi.builtin.BffModelResInfoImpl;
import com.inspur.edp.cef.spi.entity.resourceInfo.ModelResInfo;

public class AuthUtils {
    public static void buildAuthInfo(
            AuthInfo info,
            String extendType,
            String extend1,
            String extend2,
            String extend3,
            String extend4,
            String extend5) {
        info.setExtType(extendType);
        info.setExtend1(extend1);
        info.setExtend2(extend2);
        info.setExtend3(extend3);
        info.setExtend4(extend4);
        info.setExtend5(extend5);
    }

    public static void buildAuthInfo(
            AuthInfo info,
            String extendType,
            String extend1,
            String extend2,
            String extend3,
            String extend4,
            String extend5,
            String sourceType) {
        buildAuthInfo(info, extendType, extend1, extend2, extend3, extend4, extend5);
        info.setSourceType(sourceType);
    }

    public static void buildAuthInfo(AuthInfo info, ModelResInfo resInfo, String voId,
                                     String configId) {
        String extendType = "VM";
        String e1 = voId;
        String e2 = null, e3 = null, e4 = null, e5 = null;
        String authType = null;
        if (resInfo != null && resInfo instanceof BffModelResInfoImpl) {
            BffAuthConfig authConfig = ((BffModelResInfoImpl) resInfo).getAuthConfig();
            if (authConfig != null) {
                e2 = authConfig.getExtend2();
                e3 = authConfig.getExtend3();
                e4 = authConfig.getExtend4();
                e5 = authConfig.getExtend5();
                authType = authConfig.getAuthType();
            }
        }
        buildAuthInfo(info, extendType, e1, e2, e3, e4, e5);
        info.setSourceType(configId);
        info.setAuthType(authType);
    }
}
